<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>L2LB: netfilter.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Gerado por Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="annotated.html"><span>Estruturas&nbsp;de&nbsp;dados</span></a></li>
      <li class="current"><a href="files.html"><span>Ficheiros</span></a></li>
    </ul>
  </div>
<h1>netfilter.h</h1><a href="netfilter_8h.html">Ir para a documentação deste ficheiro.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00006"></a>00006 <span class="preprocessor">#ifndef NETFILTER_H_</span>
<a name="l00007"></a>00007 <span class="preprocessor"></span><span class="preprocessor">#define NETFILTER_H_</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span>
<a name="l00015"></a><a class="code" href="netfilter_8h.html#e197bbd3c720b235dff80a8abc7250dd">00015</a> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="netfilter_8h.html#e197bbd3c720b235dff80a8abc7250dd" title="NF_IP_LOCAL_IN hook.">nlb_hook_in</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> hooknum, <span class="keyword">struct</span> sk_buff **skb, <span class="keyword">const</span> <span class="keyword">struct</span> net_device *in, <span class="keyword">const</span> <span class="keyword">struct</span> net_device *out, <span class="keywordtype">int</span> (*okfn)(<span class="keyword">struct</span> sk_buff *)) 
<a name="l00016"></a>00016 {
<a name="l00017"></a>00017         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ret;
<a name="l00018"></a>00018         <span class="keyword">struct </span>iphdr *iph = (*skb)-&gt;nh.iph;
<a name="l00019"></a>00019         <span class="keyword">struct </span><a class="code" href="structnlb__affinity.html" title="Afinidade entre um cliente e um servidor do cluster.">nlb_affinity</a> *affinidade;
<a name="l00020"></a>00020         
<a name="l00021"></a>00021         <span class="comment">//Teste... APENAS ping!</span>
<a name="l00022"></a>00022         <span class="keywordflow">if</span>(iph-&gt;protocol != IPPROTO_ICMP)
<a name="l00023"></a>00023                 <span class="keywordflow">return</span> NF_ACCEPT;
<a name="l00024"></a>00024 
<a name="l00025"></a>00025         <span class="comment">//Caso o pacote nao esteja chegando atraves da interface do cluster,</span>
<a name="l00026"></a>00026         <span class="comment">//entao simplesmente aceita o pacote</span>
<a name="l00027"></a>00027         <span class="keywordflow">if</span>(in != <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>)
<a name="l00028"></a>00028                 <span class="keywordflow">return</span> NF_ACCEPT;
<a name="l00029"></a>00029         
<a name="l00030"></a>00030         <span class="comment">//Caso haja alguma afinidade previamente estabelecida entre um </span>
<a name="l00031"></a>00031         <span class="comment">//cliente e um servidor, rapidamente aceita ou dropa o pacote</span>
<a name="l00032"></a>00032         affinidade = <a class="code" href="hash-afinidades_8h.html#cd0b9a162ec55cddc882ca2070daf745" title="Procura na tabela HASH por uma afinidade entre um cliente e um servidor.">hash_lookup</a>(&amp;iph-&gt;saddr);
<a name="l00033"></a>00033         
<a name="l00034"></a>00034         <span class="keywordflow">if</span>(affinidade) 
<a name="l00035"></a>00035         {
<a name="l00036"></a>00036                 <span class="keywordflow">if</span>(affinidade-&gt;<a class="code" href="structnlb__affinity.html#0a05b92eaec72d6ee4de0a54cd658036">node</a> == <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#7ccd7197eb601ffee1b0f6209578e9a2">my_node</a>)
<a name="l00037"></a>00037                         <span class="keywordflow">return</span> NF_ACCEPT;
<a name="l00038"></a>00038                 <span class="keywordflow">else</span>
<a name="l00039"></a>00039                         <span class="keywordflow">return</span> NF_DROP;
<a name="l00040"></a>00040         }
<a name="l00041"></a>00041         
<a name="l00042"></a>00042         write_lock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00043"></a>00043         
<a name="l00044"></a>00044         <span class="comment">//Cria a afinidade entre o cliente o servidor que ira atender sua requisicao</span>
<a name="l00045"></a>00045         <a class="code" href="hash-afinidades_8h.html#2d316c6293294b551cb94309a0a70942" title="Cria uma afinidade entre um cliente e um servidor específico do cluster.">hash_add</a>(&amp;iph-&gt;saddr, <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a>);
<a name="l00046"></a>00046         
<a name="l00047"></a>00047         <span class="comment">//Caso o proximo servidor do cluster seja o meu, entao aceita o pacote</span>
<a name="l00048"></a>00048         <span class="keywordflow">if</span>(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a> == <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#7ccd7197eb601ffee1b0f6209578e9a2">my_node</a>)       
<a name="l00049"></a>00049                 ret = NF_ACCEPT;
<a name="l00050"></a>00050         <span class="keywordflow">else</span>
<a name="l00051"></a>00051                 ret = NF_DROP;
<a name="l00052"></a>00052                 
<a name="l00053"></a>00053         <span class="comment">//Obtem o servidor que ira atender a proxima requisicao ao cluster</span>
<a name="l00054"></a>00054         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a> = <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a>-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a>;
<a name="l00055"></a>00055         
<a name="l00056"></a>00056         write_unlock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00057"></a>00057         
<a name="l00058"></a>00058         <span class="keywordflow">return</span> ret;
<a name="l00059"></a>00059 };
<a name="l00060"></a>00060 
<a name="l00064"></a><a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9">00064</a> <span class="keyword">static</span> <span class="keyword">struct </span>nf_hook_ops <a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9" title="Estrtutra com informações necessárias para inicializar o uso do Netfilter.">nlb_ops</a>;
<a name="l00065"></a>00065 
<a name="l00069"></a><a class="code" href="netfilter_8h.html#bf19d764f0af6d861e95cb83707589a7">00069</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="netfilter_8h.html#bf19d764f0af6d861e95cb83707589a7" title="Inicializa a interceptação dos pacotes com o Netfilter.">nlb_netfilter_init</a>(<span class="keywordtype">void</span>)
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071         <span class="comment">//Registra os hooks no Netfilter</span>
<a name="l00072"></a>00072         <a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9" title="Estrtutra com informações necessárias para inicializar o uso do Netfilter.">nlb_ops</a>.owner = THIS_MODULE;
<a name="l00073"></a>00073         <a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9" title="Estrtutra com informações necessárias para inicializar o uso do Netfilter.">nlb_ops</a>.pf = PF_INET;
<a name="l00074"></a>00074         <a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9" title="Estrtutra com informações necessárias para inicializar o uso do Netfilter.">nlb_ops</a>.priority = NF_IP_PRI_FILTER;
<a name="l00075"></a>00075         <a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9" title="Estrtutra com informações necessárias para inicializar o uso do Netfilter.">nlb_ops</a>.hooknum = NF_IP_LOCAL_IN; <span class="comment">//NF_IP_PRE_ROUTING</span>
<a name="l00076"></a>00076         <a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9" title="Estrtutra com informações necessárias para inicializar o uso do Netfilter.">nlb_ops</a>.hook = <a class="code" href="netfilter_8h.html#e197bbd3c720b235dff80a8abc7250dd" title="NF_IP_LOCAL_IN hook.">nlb_hook_in</a>;
<a name="l00077"></a>00077         
<a name="l00078"></a>00078         <span class="keywordflow">return</span> nf_register_hook(&amp;<a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9" title="Estrtutra com informações necessárias para inicializar o uso do Netfilter.">nlb_ops</a>);
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080 
<a name="l00084"></a><a class="code" href="netfilter_8h.html#dfb4739620e1a1d113735757982d0d7e">00084</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="netfilter_8h.html#dfb4739620e1a1d113735757982d0d7e" title="Interrompe a interceptação dos pacotes com o Netfilter.">nlb_netfilter_exit</a>(<span class="keywordtype">void</span>)
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086         nf_unregister_hook(&amp;<a class="code" href="netfilter_8h.html#8beaa7c9da49f7fa797b85a0feeda3f9" title="Estrtutra com informações necessárias para inicializar o uso do Netfilter.">nlb_ops</a>);
<a name="l00087"></a>00087         <span class="keywordflow">return</span> 0;
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 <span class="preprocessor">#endif </span><span class="comment">/*NETFILTER_H_*/</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Gerado em Wed Sep 10 23:05:55 2008 para L2LB por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>
